package com.bestcem.xm.award.mq.receiver.biz.kafka;

import com.bestcem.xm.award.mq.dto.*;
import com.bestcem.xm.award.mq.receiver.biz.AwardConsumers;
import com.bestcem.xm.award.mq.receiver.biz.ReceiverService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

@Slf4j
@Component
@ConditionalOnProperty(prefix = "application", name = "mqType", havingValue = "kafka")
public class KafkaConsumers implements AwardConsumers {

    private ReceiverService receiverService;

    @Autowired
    public void setReceiverService(ReceiverService receiverService) {
        this.receiverService = receiverService;
    }

    /**
     * 延迟消息:开始抽奖奖励消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<DrawAwardStartDTO>> awardDrawStart() {
        return msg -> receiverService.awardDrawStart(msg);
    }

    /**
     * 延迟消息:奖励通知抽奖结束
     */
    @Bean
    @Override
    public Consumer<GenericMessage<DrawAwardStopDTO>> awardDrawStop() {
        return msg -> receiverService.awardDrawStop(msg);
    }

    /**
     * 延迟消息:奖励异步消费清理临时表通知消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<TempCleanDTO>> awardTempClean() {
        return msg -> receiverService.awardTempClean(msg);
    }

    /**
     * 延迟消息:奖励消费红包开始消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<RedPacketAwardStartDTO>> awardRedPacketStart() {
        return msg -> receiverService.awardRedPacketStart(msg);
    }

    /**
     * 延迟消息:奖励消费红包结束消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<RedPacketAwardStopDTO>> awardRedPacketStop() {
        return msg -> receiverService.awardRedPacketStop(msg);
    }

    /**
     * 延迟消息:励消费查询红包发放结果消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<RedPacketAwardSendingDTO>> awardRedPacketSending() {
        return msg -> receiverService.awardRedPacketSending(msg);
    }

    /**
     * 延迟消息:奖励消费奖励开始消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<AwardStartDTO>> awardAwardStart() {
        return msg -> receiverService.awardAwardStart(msg);
    }

    /**
     * 延迟消息:奖励消费奖励结束消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<AwardStopDTO>> awardAwardStop() {
        return msg -> receiverService.awardAwardStop(msg);
    }

    /**
     * 奖励消费项目删除消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<ProjectDeleteDTO>> awardProjectDelete() {
        return msg -> receiverService.awardProjectDelete(msg);
    }

    /**
     * 奖励消费中奖短信通知消息
     */
    @Bean
    @Override
    public Consumer<GenericMessage<DrawAwardSendSmsDTO>> awardDrawSms() {
        return msg -> receiverService.awardDrawSms(msg);
    }
}
